package com.gitee.taotaojs.mybootsuper.vo;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author TaoTaojs
 * @date 2020/9/1 5:07 PM
 * <p>Description</p>
 * <h2>功能描述</h2>
 * HTTP结果封装
 * <h3>主要功能：</h3>
 * <ol>
 *     <li>http返回信息及公用方法</li>
 * </ol>
 * <h3>关联类</h3>
 * <p>参考链接：</p>
 * <h2>更新日志</h2>
 * [author]        [time]                      [version]          [desc]
 * TaoTaojs        2020/9/1 5:07 PM             V1.0              http返回信息及公用方法
 */

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class HttpResult {

    /**  */
    private int code = 200;
    /**  */
    private String msg;
    /**  */
    private Object data;

    /**
     * 返回错误信息
     * @return 错误信息
     */
    public static HttpResult error() {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, "未知异常，请联系管理员");
    }

    /**
     * 返回错误信息
     * @param msg 错误信息
     * @return 错误信息
     */
    public static HttpResult error(String msg) {
        return error(HttpStatus.SC_INTERNAL_SERVER_ERROR, msg);
    }

    /**
     * 返回错误信息+编码
     * @param code 错误码
     * @param msg 错误信息
     * @return 错误信息
     */
    public static HttpResult error(int code, String msg) {
        HttpResult r = new HttpResult();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    /**
     * 成功
     * @param msg 成功信息
     * @return 成功信息
     */
    public static HttpResult ok(String msg) {
        HttpResult r = new HttpResult();
        r.setMsg(msg);
        return r;
    }

    /**
     * 成功
     * @param data 成功数据
     * @return 成功信息
     */
    public static HttpResult ok(Object data) {
        HttpResult r = new HttpResult();
        r.setData(data);
        return r;
    }

    /**
     * 成功
     * @return 成功信息
     */
    public static HttpResult ok() {
        return new HttpResult();
    }

}
